limsPageContentConfig.editPage = {

    getPageConfigTabParam: function () {
        let _this = this;
        return {
            type: 'tab',
            panels: [{
                title: 'T_LIMS_PAGE_CONTENT_PAGE.LOGINPAGE',
                items: [{
                    type: 'form',
                    id: _this.idManager.loginPageForm,
                    service : 'limsPageContentConfigServiceImpl',
                    url: limsPageContentConfig.pageConfigUrl + '/1',
                    fields: limsPageContentConfig.getLoginPageFields(),
                    onLoadSuccess : function(data) {
                        Gikam.post(IFM_CONTEXT + '/core/module/item/files/queries', Gikam.getJsonWrapper({
                            f : {
                                targetId : 'T_LIMS_PAGE_CONTENT_CONFIG$1',
                                bizCategory_SEQ : 'LOGOPIC'
                            },
                            n : -1,
                            s : 50
                        })).done(function(fileList) {
                            if (!Gikam.isEmpty(fileList.rows)) {
                                Gikam.getComp(_this.idManager.loginPageForm).setData({
                                    ext$ : {
                                        logopic : fileList.rows[0].downloadUrl
                                    }
                                }, false)
                            }
                        });
                    }
                }]
            }, {
                title: 'T_LIMS_PAGE_CONTENT_PAGE.INDEXPAGE',
                items: [{
                    type: 'form',
                    id: _this.idManager.indexPageForm,
                    service: 'limsPageContentConfigServiceImpl',
                    url: limsPageContentConfig.pageConfigUrl + '/2',
                    fields: limsPageContentConfig.getIndexPageFields(),
                    onLoadSuccess : function(data) {
                        Gikam.post(IFM_CONTEXT + '/core/module/item/files/queries', Gikam.getJsonWrapper({
                            f : {
                                targetId : 'T_LIMS_PAGE_CONTENT_CONFIG$2',
                                bizCategory_SEQ : 'LOGOPIC'
                            },
                            n : -1,
                            s : 50
                        })).done(function(fileList) {
                            if (!Gikam.isEmpty(fileList.rows)) {
                                Gikam.getComp(_this.idManager.indexPageForm).setData({
                                    ext$ : {
                                        logopic : fileList.rows[0].downloadUrl
                                    }
                                }, false)
                            }
                        });
                    }
                }]
            }],
        }
    },

    uploadLogoPic : function(idStr, bizId) {
        var configForm = Gikam.getComp(idStr);
        Gikam.post(IFM_CONTEXT + '/core/module/item/files/queries', Gikam.getJsonWrapper({
            f : {
                targetId : 'T_LIMS_PAGE_CONTENT_CONFIG$' + bizId,
                bizCategory_SEQ : 'LOGOPIC'
            },
            n : -1,
            s : 50
        })).done(function(r) {
            if (r.total > 0) {
                Gikam.confirm('GIKAM.BUTTON.CONFIRM', 'LIMS.PAGE.CONFIG.LOGO.OVERRIDE', function() {
                    Gikam.create('simpleUploader', {
                        id : 'page-config-logo-pic-uploader',
                        dbTable : 'T_LIMS_PAGE_CONTENT_CONFIG',
                        bizId : bizId,
                        bizCategory : 'LOGOPIC',
                        accept : 'image',
                        multiple : false,
                        onAfterClose : function(fileList) {
                            if (fileList.length > 0) {
                                Gikam.del(IFM_CONTEXT + '/core/module/item/files', Gikam.getJsonWrapper(null, [ '', r.rows ]));
                                Gikam.getJson(Gikam.printf(IFM_CONTEXT + '/core/module/item/files/{id}', {
                                    id : fileList[0].id
                                })).done(function(r) {
                                    configForm.setData({
                                        ext$ : {
                                            logopic : r.downloadUrl
                                        }
                                    }, false)
                                });
                            }
                        }
                    });
                })
            } else {
                Gikam.create('simpleUploader', {
                    id : 'page-config-logo-pic-uploader',
                    dbTable : 'T_LIMS_PAGE_CONTENT_CONFIG',
                    bizId : bizId,
                    bizCategory : 'LOGOPIC',
                    accept : 'image',
                    multiple : false,
                    onAfterClose : function(fileList) {
                        if (fileList.length === 0) {
                            return;
                        }
                        Gikam.getJson(Gikam.printf(IFM_CONTEXT + '/core/module/item/files/{id}', {
                            id : fileList[0].id
                        })).done(function(r) {
                            configForm.setData({
                                ext$ : {
                                    logopic : r.downloadUrl
                                }
                            }, false)
                        });
                    }
                });
            }
        });
    },

    idManager: {
        layout: 'lims-page-config-edit-list-layout',
        loginPageForm: 'lims-logpage-config-form',
        indexPageForm: 'lims-indexpage-config-form',
    },

    create : function() {
        let _this = this;
        Gikam.create('layout', {
            id : _this.idManager.layout,
            renderTo : workspace.window.$dom,
            center : {
                items : [ this.getPageConfigTabParam() ]
            }
        });
    },

    init : function() {
        this.create();
    }
};
